package com.wwlwxg.jmh;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class JMHSample_01_HelloWorld {

    @State(Scope.Benchmark)
    public static class SharedState{
        @Setup
        public void setupOnTrial() {
            System.out.println("before trial");
        }

        @Setup(Level.Iteration)
        public void setupOnIteration() {
            System.out.println("before iteration");
        }
    }

    @Benchmark
    @BenchmarkMode(Mode.Throughput)
    @Warmup(iterations = 1)
    @Measurement(iterations = 3)
    @OutputTimeUnit(TimeUnit.MILLISECONDS)
    public double f(SharedState sharedState) {
        return Math.log(Math.PI);
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(JMHSample_01_HelloWorld.class.getSimpleName())
                .result("./jmh_result")
                .resultFormat(ResultFormatType.JSON)
                .build();
        new Runner(opt).run();
    }

    public void wellHelloThree() {

    }
}
